import React, { Component } from 'react'
import CommentInput from './CommentInput'
import CommentList from './CommentList'


export default class CommentApp extends Component {

    state = {
        comments: []
    }

    handleSubmitComment = (comment) => {
        console.log(comment);
        if (!comment) return
        if (!comment.username) return alert('请输入用户名')
        if (!comment.content) return alert('请输入评论内容')
        this.setState({
           comments:[
               comment,
               ...this.state.comments
           ]
        })
    }
    render() {
        return (
            <div className='wrapper'>
                dffd sd dfdsffdfgfhgh撒旦撒
                <CommentInput onSubmit={this.handleSubmitComment} />
                <CommentList comments={this.state.comments} />
            </div>
        )
    }
}
